﻿<UserControl x:Class="TriviaViews.Views.GameView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:converter="clr-namespace:TriviaViews.Converters"
             xmlns:invoke ="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:local ="clr-namespace:TriviaViews"
            
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="450">
    <UserControl.Resources>
        <converter:BoolToColorConverter x:Key="colorConverter"></converter:BoolToColorConverter>
        <converter:BoolToStringConverter x:Key="stringConverter"></converter:BoolToStringConverter>
        <converter:BoolToUriSourceConverter x:Key="uriConverter"></converter:BoolToUriSourceConverter>


        <DataTemplate x:Key="AnswereTamplate">
            <Label Content="{Binding AnswerString}"  FontSize="15" FontStyle="Oblique" ></Label>
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="20*"></RowDefinition>
            <RowDefinition Height="60*"></RowDefinition>
            <RowDefinition Height="20*"></RowDefinition>
        </Grid.RowDefinitions>

        <StackPanel Grid.ColumnSpan="2" Height="auto" Width="auto">
            <Label Content="{Binding CurrentQuestion.QuestionString}" FontSize="17" Margin="5"/>
            <Border BorderBrush="Brown" BorderThickness="2" Height="200" Width="200">
                <Image Source="{Binding CurrentQuestion.QuestionImage}"></Image>
            </Border>
        </StackPanel>

        <Border BorderBrush="DarkSlateGray" BorderThickness="3" Grid.Row="1" Grid.ColumnSpan="2">
            <Grid>
                <ListView x:Name="list"  Grid.Row="1" ItemTemplate="{StaticResource AnswereTamplate}" ItemsSource="{Binding QuestionAnswers}" SelectedItem="{Binding SelectedAnswer}" SelectionMode="Single" Visibility="{Binding IsAnswersVisible}">

                </ListView>
                <Label Content="{Binding SelectedAnswer.IsRightAnswer, Converter={StaticResource stringConverter},ConverterParameter=Label}"  Foreground="{Binding SelectedAnswer.IsRightAnswer, Converter={StaticResource colorConverter}}" FontSize="30" Visibility="{Binding IsLableVisible}"></Label>
                <StackPanel Visibility="{Binding IsGameFinished}">
                    <Label  FontSize="20">Game Finished If you Want To Play</Label>
                    <Label FontSize="20">Again Press "Start Playing".</Label>
                </StackPanel>

            </Grid>
        </Border>

        <Label FontSize="15"  Content="{Binding CurrentQuestion.Clue}" Visibility="{Binding IsClueVisible}" Background="Beige"  Grid.Row="1" Margin="40,143,40,35" Grid.ColumnSpan="2"></Label>
        <StackPanel Grid.Row="2" Orientation="Horizontal" Grid.ColumnSpan="2">
            <StackPanel>
                <Label Content="{Binding Time}" Height="36" Width="79" Margin="5" Visibility="{Binding IsAnswersVisible}">
                </Label>
            </StackPanel>
            <StackPanel Grid.Row="2" Orientation="Horizontal">
                <Button Width ="auto" HorizontalAlignment="Right" Background="Goldenrod" FontWeight="Black" Command="{Binding NextQuestionCommand}">Next Question=></Button>
                <Button HorizontalAlignment="Left" Width="auto" Command="{Binding ShowClueCommand}" IsEnabled="{Binding IsAnswersVisible}">Press for Question Clue!</Button>
            </StackPanel>
        </StackPanel>

        <MediaElement Source="{Binding SelectedAnswer.IsRightAnswer,Converter={StaticResource uriConverter}}"  
                      LoadedBehavior="Manual" 
                      UnloadedBehavior="Manual" Volume="0.9" 
                      Name="mediaelement" Grid.ColumnSpan="2">
            <invoke:Interaction.Triggers>
                <invoke:EventTrigger 
                    SourceName="list" 
                    EventName="SelectionChanged">
                    <local:ControlMediaElementAction></local:ControlMediaElementAction>
                </invoke:EventTrigger>
            </invoke:Interaction.Triggers>
        </MediaElement>
    </Grid>
</UserControl>
